<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="layui/css/layui.css">
</head>
<body>
<div class="layui-fluid">
  <table class="layui-hide" id="attqu" lay-filter="attqu"></table>
</div>

<script id="toolbar"  type="text/html">
<!--
    <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
    <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
-->
    <button class="layui-btn layui-btn-sm" lay-event="add">保留按钮</button>
     <div class="layui-inline">
     <div class="layui-input-inline" style="width:150px;height:38px;">
       <input type="text" name="likeName" id="likeName" required lay-verify="required" placeholder="请输入工号" class="layui-input">
     </div>
     <div class="layui-inline">
       <button class="layui-btn layui-btn-sm"  data-type="reload" id="search"><i class="layui-icon">&#xe615;</i>搜索</button>
     </div>  
    </div>
</script>

<script type="text/html" id="addLayer">
    <!-- 添加模态框 -->
<div>
     <form action="/addAttqu" class="layui-form" id="addForm">
      
     <div class="layui-form-item">
       <label class="layui-form-label">月份</label>
       <div class="layui-input-inline">
          <input class="layui-input" type="text" name="month" id="month" lay-verify="requeired">
       </div>   
     </div>
     <div class="layui-form-item">
      <div class="layui-inline">
       <div>
       <label class="layui-form-label">工号</label>
       <div class="layui-input-inline">
          <input class="layui-input" type="text" name="empNo" id="empNo">
       </div>
       </div>
       <div>
       <label class="layui-form-label">姓名</label>
       <div class="layui-input-inline">
          <input class="layui-input" type="text" name="name" id="name">
       </div>
       </div>
      </div>
     </div>
     <div class="layui-form-item">
      <div class="layui-inline">
       <label class="layui-form-label">加班</label>
       <div class="layui-input-inline">
          <input class="layui-input" type="text" name="overtime" id="overtime">
       </div>
       <div class="layui-form-mid layui-word-aux">小时</div>
       <label class="layui-form-label">出差</label>
       <div class="layui-input-inline">
          <input class="layui-input" type="text" name="businessTrip" id="businessTrip">
       </div>
       <div class="layui-form-mid layui-word-aux">天</div>
       </div>     
     </div>
     <div class="layui-form-item">
      <div class="layui-inline">
       <label class="layui-form-label">请假</label>
       <div class="layui-input-inline">
          <input class="layui-input" type="text" name="vacate" id="vacate">
       </div>
       <div class="layui-form-mid layui-word-aux">天</div>
       <label class="layui-form-label">迟到/早退</label>
       <div class="layui-input-inline">
          <input class="layui-input" type="text" name="lateOrEarly" id="lateOrEarly">
       </div>
       <div class="layui-form-mid layui-word-aux">次</div>
       </div>     
     </div>
    <div class="layui-form-item">
       <label class="layui-form-label">加班补贴</label>
       <div class="layui-input-inline">
         <input class="layui-input" type="text" name="oSubsidy" id="oSubsidy">
       </div>
     <div class="layui-form-mid layui-word-aux">元</div>   
     </div>
    <div class="layui-form-item">
       <label class="layui-form-label">出差补贴</label>
       <div class="layui-input-inline">
         <input class="layui-input" type="text" name="bSubsidy" id="bSubsidy">
       </div>
      <div class="layui-form-mid layui-word-aux">元</div>   
    </div>
    <div class="layui-form-item">
       <label class="layui-form-label">迟到/早退扣款</label>
       <div class="layui-input-inline">
         <input class="layui-input" type="text" name="lSubsidy" id="lSubsidy">
       </div>  
       <div class="layui-form-mid layui-word-aux">元</div> 
     </div>
    <div class="layui-form-item">
       <label class="layui-form-label">请假扣款</label>
       <div class="layui-input-inline">
         <input class="layui-input" type="text" name="vSubsidy" id="vSubsidy">
       </div>  
       <div class="layui-form-mid layui-word-aux">元</div> 
     </div>
     </form> 
    </div>
</script>

<script src="layui/layui.js"></script> 
<script th:inline="none">
  layui.use('table',function(){
	  var table=layui.table;
	  var $=layui.jquery;
	  table.render({
		  elem:'#attqu',
		  url:'/getEmpBaseInfo',
		  method:'post',
		  toolbar:'#toolbar',
		  defaultToolbar:['filter','exports','print',{title:'提示',layEvent:'LAYTABLE_TIPS',icon:'layui-icon-tips'}],
		  title:'员工信息表',
		  cols:[[
		    	 {type:'checkbox',fixed:'left'},
		    	 {field:'id',title:'ID',width:70,fixed:'left',unresize:true,sort:true}
		    	 ,{field:'empNo',title:'工号',width:100,sort:true}
		    	 ,{field:'name', title:'姓名',width:120,sort: true}
		    	 ,{field:'sex', title:'性别',width:80}
		    	 ,{field:'phone', title:'电话号码',width:130,sort: true}
		    	 ,{field:'depName', title:'部门名'}
		    	 ,{field:'position', title:'职位',sort: true}
		    	 ,{fixed: 'right', title:'操作', toolbar: '#bar'}
		     ]],
		     id:'testreload',
		     page:true
	  });
	  
	  //表格数据重载
	  var active={
			  reload:function(){
				  var demoReload=$('#likeName');
				  table.reload('testreload',{
					  page:{
						  curr:1
					  },
					  where:{
						  //参数name的名称要与控制器中的一致
						  empNo:demoReload.val()
					  },
					  url:'/searchEmp',
					  method:'post'
				  });
			  }
	  };
	  
	  //搜索按钮事件
	  
	  $("#search").on('click',function(){
		  var type=$(this).data('type');
		  active[type]?active[type].call(this):'';
	  });
	  
	  
	  //头部工具栏
	  table.on('toolbar(attqu)',function(obj){
		  var checkStatus=table.checkStatus(obj.config.id);
		  switch(obj.event){
		  case 'getCheckLength':
			  var data=checkStatus.data;
			  layer.msg('选中了：'+data.length+'个');
		  break;
		  case 'isAll':
			  layer.msg(checkStatus.isAll?'全选':'未全选');
		  break;
		  case 'LAYTABLE_TIPS':
			  layer.alert('这是工具栏右侧自定义的一个图标按钮');
		  break;
		  };
	  });
	  
	  //行工具栏
	  table.on('tool(attqu)',function(obj){
		  var data=obj.data;
		  if(obj.event==='addAttqu'){
			 layui.use('form',function(){
				 var form=layui.form;
				 var $=layui.jquery;
				 var addIndex=layer.open({
					 formType:1,
					 title:'增加考勤量化信息',
					 btn:['确认','取消'],
					 area:['450px','450px'],
					 content:$('#addLayer').html(),
					 yes:function(addIndex,layero){
						     var month=$("#month").val();
						     var empNo=$("#empNo").val();
						     var name=$("#name").val();
						     var overtime=$("#overtime").val();
						     var businessTrip=$("#businessTrip").val();
						     var vacate=$("#vacate").val();
						     var lateOrEarly=$("#lateOrEarly").val();
						     var oSubsidy=$("#oSubsidy").val();
						     var bSubsidy=$("#bSubsidy").val();
						     var lSubsidy=$("#lSubsidy").val();
						     var vSubsidy=$("#vSubsidy").val();
						  $.ajax({
							  url:'/addAttqu',
							  method:'post',
							  contentType:"application/json;charset=utf-8",
							  data:JSON.stringify({month:month,empNo:empNo,name:name,overtime:overtime,businessTrip:businessTrip,vacate:vacate,lateOrEarly:lateOrEarly,oSubsidy:oSubsidy,bSubsidy:bSubsidy,lSubsidy:lSubsidy,vSubsidy:vSubsidy}),
							  success:function(data){
								  if(data){
								      layer.msg("添加成功");
								      //window.setTimeout(function(){window.location.reload();},500)
								  }else{
									  layer.alert("添加失败,该员工本月已经添加过了！");
								  }
							  },
							  error:function(data){
								  layer.msg("添加失败");
								 // layer.msg(account1);
							  }
						  });
					 },
					 btn2:function(addIndex,layero){
						 layer.close(addIndex);
					 },
					 success:function(){
						 layui.use('laydate',function(){
							   var laydate=layui.laydate;
							   laydate.render({
								   elem:'#month',
								   type:'month',
							   });
						   });
						 $("[name='empNo']").val(data.empNo);
						  $("[name='name']").val(data.name);
						  form.render();
					 },
				 });
			 });
		  }else if(obj.event==='sign'){
			 layui.use('form',function(){
				 var form=layui.form;
				 var $=layui.jquery;
			 var editIndex=layer.open({
				  formType:1,
				  title:'修改信息',
				  btn:['确认','取消'],
				  yes:function(editIndex,layero){
					  
					//获取表单的值，必须再次出获取，若在给弹窗赋值后再获取，则获取到的仍是原始数据，相当于加载了一个空的表单，然后弹窗赋值，然后获取表单的值
					
					 // layer.msg(account);

					 
				  },
				  btn2:function(editIndex,layero){
					  layer.close(editIndex);
				  },
				//  end:function(){parent.reload();},
				  area:['450px','450px'],
				  content:$('#editLayer').html(),
				  success:function(layero,index){ 
					  //给个控件赋值
						 $("[name='id']").val(data.id);
						 $("[name='empNo']").val(data.empNo);
						 $("[name='name']").val(data.name);
						 $("[name='birthday']").val(data.birthday);
						// $("[name='depNo']").val(data.depName);
				         switch(data.depName){
				         case '总裁办公室':
				        	 $("[name='depNo']").val(1);
				        	 break;
				         case '人力资源部':
				        	 $("[name='depNo']").val(2);
				        	 break;
				         case '销售部':
				             $("[name='depNo']").val(3);
				             break;
				         case '技术部':
				        	 $("[name='depNo']").val(4);
				        	 break;
				         case '财务部':
				        	 $("[name='depNo']").val(5);
				        	 break;
				         }
						 $("[name='position']").val(data.position);
						 $("[name='sex']").val(data.sex);
						 $("[name='phone']").val(data.phone);
						 $("[name='slary']").val(data.slary);
						 layui.use('laydate',function(){
							   var laydate=layui.laydate;
							   laydate.render({
								   elem:'#birthday',
								   type:'month',
							   });
						   });
						 form.render()},
				  });						 
			 });
		  }
	  });

  });
</script>
</body>
</html>